home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 February / Macworld (1999-02).dmg / Serious Demos / Portfolio 4.0.1 / Scripting Extras / Find Duplicates.txt < prev    next >
Text File  |  1998-09-15  |  2KB  |  50 lines

  1. -- Check to make sure Portfolio is running
  2. tell application "Finder"
  3.     set P_app to every process whose name contains "Portfolio"
  4.     if P_app is {} then
  5.         display dialog ¬
  6.             "Portfolio must be running for this script to operate." buttons {"OK"} default button {"OK"}
  7.         return
  8.     end if
  9. end tell
  10.  
  11.  
  12. tell application "Portfolio"
  13.     activate
  14.     
  15.     --Check to make sure the field "Duplicate" exists
  16.     set lFields to the name of every field of the first record of the front gallery
  17.     if lFields does not contain "Duplicate" then
  18.         display dialog "This script requires the catalog to have a custom integer field titled 'Duplicate'."
  19.         return
  20.     end if
  21.     
  22.     
  23.     -- Find All
  24.     set theQuery to "Filename" & tab & "exists"
  25.     find record of front gallery matching theQuery in all records
  26.     sort front gallery by "Filename"
  27.     
  28.     -- Reset the Duplicate field
  29.     set field "Duplicate" of every record of front gallery to "0"
  30.     
  31.     set theCount to count every record of front gallery
  32.     set oldFName to ""
  33.     
  34.     -- Loop through all the records, checking to see if two consecutive records have 
  35.     -- the same file name. If they do, mark both as duplicates
  36.     repeat with i from 1 to theCount
  37.         set newFName to filename of record i of front gallery
  38.         if newFName = oldFName then
  39.             set field "Duplicate" of records (i - 1) through i of front gallery to "1"
  40.         end if
  41.         set oldFName to newFName
  42.     end repeat
  43.     
  44.     -- Find Records marked duplicate
  45.     set theQuery to "Duplicate" & tab & "equals" & tab & "1"
  46.     find record of front gallery matching theQuery in all records
  47.     sort front gallery by "Filename"
  48.     
  49. end tell
  50.